package com.intellagric.controller.module.trace_company;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.module.traceability.CompanyVo;
import com.intellagric.pojo.TraceCompany;
import com.intellagric.service.traceability.trace_company.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.UUID;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/11/7
 * @DESC： 公司信息管理
 */
@Controller
public class CompanyController {

    @Autowired
    private CompanyService companyService;

    /**
     * 添加公司信息
     * @Param 
     * @return ResponseMessage
     */
    @RequestMapping("/company/add")
    @ResponseBody
    public ResponseMessage add(TraceCompany company) {
        //初始化数据
        company.setId(UUID.randomUUID().toString().replaceAll("-",""));
        company.setCreateDate(new Date());
        company.setUpdateDate(new Date());
        return companyService.addCompany(company);
    }

    /**
     * 删除公司信息
     * @Param id
     * @return ResponseMessage
     */
    @RequestMapping("/company/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return companyService.deleteCompany(id);
    }

    /**
     * 修改公司信息
     * @Param company
     * @return ResponseMessage
     */
    @RequestMapping("/company/edit")
    @ResponseBody
    public ResponseMessage edit(TraceCompany company) {
        company.setUpdateDate(new Date());
        return companyService.editCompany(company);
    }

    /**
     * 查询公司信息
     * @return TraceCompany
     */
    @RequestMapping("/company/{id}")
    @ResponseBody
    public TraceCompany get(@PathVariable String id) {
        return companyService.getCompanyById(id);
    }

    /**
     * 查询公司信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/company/list")
    @ResponseBody
    public LayuiDataGridResult getList() {
        return companyService.getCompanyList();
    }

    /**
     * 分页查询公司信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/company/page")
    @ResponseBody
    public LayuiDataGridResult getPage(int page ,int limit) {
        return companyService.getCompanyPage(page,limit);
    }

    /**
     * 根据Vo类型分页查询公司信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/company/query")
    @ResponseBody
    public LayuiDataGridResult getPage(int page ,int limit,CompanyVo companyVo) {
        return companyService.getCompanyByVo(page,limit,companyVo);
    }

}
